﻿<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
>
  <xsl:output method="html" indent="yes"/>
    <xsl:variable name="Header">
      <tr class="RowHeader">
        <td>
          名称
        </td>
        <td>
          值
        </td>
      </tr>
    </xsl:variable>

    <xsl:template match="/TableView">
      <html>
        <head>
          <link rel="StyleSheet" href="default.css" type="text/css" />
          <script type="text/javascript" language="javascript">
                function copy(o)
                {
                    var text=document.getElementById(o).innerText;
                    window.clipboardData.setData("text",text);
                }

          </script>
        </head>
        <body>
          <h3>
            <xsl:value-of select="@Type"/> | <xsl:value-of select="@Schema"/>.<xsl:value-of select="@Name"/>
          </h3>
          <hr></hr>
          <h4>第一部分：属性</h4>
          <table>
            <xsl:copy-of select="$Header"/>
            <xsl:for-each select="Properties/Property">
              <tr>
                <td>
                  <xsl:value-of select="Name"/>
                </td>
                <td>
                  <xsl:value-of select="Value"/>
                </td>
              </tr>
            </xsl:for-each>
          </table>
          

          <h4>第二部分：扩展属性</h4>
          <table>
            <xsl:copy-of select="$Header"/>
            <xsl:for-each select="ExtendedProperties/ExtendedProperty">
              <tr>
                <td>
                  <xsl:value-of select="Name"/>
                </td>
                <td>
                  <xsl:value-of select="Value"/>
                </td>
              </tr>
            </xsl:for-each>
          </table>


          <h4>第三部分：列</h4>

          <table>
            <tr class="RowHeader">
              <td>名称</td>
              <td>类型</td>
              <td>主键</td>
              <td>外键</td>
              <td>可空</td>
            </tr>
            
            
            
            <xsl:for-each select="Columns/Column">
              <tr>
                <td>
                  <xsl:value-of select="Name"/>
                </td>
                <td>
                  <xsl:value-of select="Type"/>
                </td>
                <td>
                  <xsl:if test="IsPrimaryKey = 'true'">
                          <SPAN style="font-family: Webdings;">a</SPAN>
                       
                  </xsl:if>
                </td>
                <td>
                  <xsl:if test="IsForeignKey = 'true'">
                          <SPAN style="font-family: Webdings;">a</SPAN>
                       
                  </xsl:if>
                </td>
                <td>
                 <xsl:if test="Nullable = 'true'">
                          <SPAN style="font-family: Webdings;">a</SPAN>
                       
                  </xsl:if>

                </td>
              </tr>

              <xsl:if test="ExtendedProperties/@Count &gt; 0">
                <tr>
                  <td></td>
                  <td colspan="4">
                    <table>
                      <xsl:copy-of select="$Header"/>
                      <xsl:for-each select="ExtendedProperties/ExtendedProperty">
                        <tr>
                          <td>
                            <xsl:value-of select="Name"/>
                          </td>
                          <td>
                            <xsl:value-of select="Value"/>
                          </td>
                        </tr>
                      </xsl:for-each>
                    </table>
                  </td>
                </tr>
              </xsl:if>
              
            </xsl:for-each>
          </table>
          
          
          <h4>第四部分：索引</h4>
          <table>
            <tr class="RowHeader">
              <td>名称</td>
              <td>聚集？</td>
            </tr>

            <xsl:for-each select="Indexes/Index">
              <tr>
                <td>
                  <xsl:value-of select="Name"/>
                </td>
                <td>
                  <xsl:if test="IsClustered = 'true'">
                          <SPAN style="font-family: Webdings;">a</SPAN>
                       
                  </xsl:if>
                </td>
              </tr>
            </xsl:for-each>
          </table>

          <h4>第五部分：触发器</h4>
          <table>
            <tr class="RowHeader">
              <td>名称</td>
              <td>插入?</td>
              <td>删除?</td>
              <td>更新?</td>
              <td>前处理?</td>
            </tr>

            <xsl:for-each select="Triggers/Trigger">
              <tr>
                <td>
                  <xsl:value-of select="Name"/>
                </td>
                <td>
                  <xsl:if test="Insert = 'true'">
                    <SPAN style="font-family: Webdings;">a</SPAN>
                  </xsl:if>
                  
                </td>
                <td>
                  <xsl:if test="Delete = 'true'">
                    <SPAN style="font-family: Webdings;">a</SPAN>
                  </xsl:if>
                </td>
                <td>
                  <xsl:if test="Update = 'true'">
                    <SPAN style="font-family: Webdings;">a</SPAN>
                  </xsl:if>
                </td>
                <td>
                  <xsl:if test="InsteadOf = 'true'">
                    <SPAN style="font-family: Webdings;">a</SPAN>
                  </xsl:if>
                </td>
              </tr>
            </xsl:for-each>
            
          </table>

          <h4>第六部分：被依赖</h4>
          <table>
            <tr class="RowHeader">
              <td>类别</td>
              <td>架构</td>
              <td>名称</td>

            </tr>

            <xsl:for-each select="ChildDependencies/ChildDependency">
              <tr>
                <td>
                  <xsl:value-of select="Type"/>
                </td>
                <td>
                  <xsl:value-of select="Schema"/>
                </td>
                <td>
                  <a>
                    <xsl:attribute name="href">
                      <xsl:value-of select="Schema"/>.<xsl:value-of select="Name"/>.xml
                    </xsl:attribute>
                    <xsl:value-of select="Name"/>
                  </a>
                </td>
   
              </tr>
              
            </xsl:for-each>
            
          </table>

          <h4>第七部分：依赖</h4>
          <table>
            <tr class="RowHeader">
              <td>类别</td>
              <td>架构</td>
              <td>名称</td>

            </tr>

            <xsl:for-each select="ParentDependencies/ParentDependency">
              <tr>
                <td>
                  <xsl:value-of select="Type"/>
                </td>
                <td>
                  <xsl:value-of select="Schema"/>
                </td>
                <td>
                  <a>
                    <xsl:attribute name="href">
                      <xsl:value-of select="Schema"/>.<xsl:value-of select="Name"/>.xml
                    </xsl:attribute>
                    <xsl:value-of select="Name"/>
                  </a>
                </td>

              </tr>

            </xsl:for-each>

          </table>


          <h4>第八部分：脚本</h4>
          <a href="javascript:copy('script');">复制</a>
          <hr></hr>
          <span id="script">
            <xsl:value-of select="Script" disable-output-escaping="yes"/>
          </span>
        </body>
      </html>

    </xsl:template>
</xsl:stylesheet>
